package com.spic.business.accident.interevents.rectificationplan.controller;

import com.spic.business.accident.interevents.rectificationplan.domain.InternalIncidentRectificationPlan;
import com.spic.business.accident.interevents.rectificationplan.service.IInternalIncidentRectificationPlanService;
import com.spic.business.common.core.workflow.IWorkFlowService;
import com.spic.business.common.core.workflow.WorkFlowController;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 内部事件整改计划Controller
 * 
 * @author 任翔
 * @date 2021-12-01
 */
@RestController
@RequestMapping("accident/rectificationPlan")
public class InternalIncidentRectificationPlanController extends WorkFlowController
{
    @Autowired
    private IInternalIncidentRectificationPlanService internalIncidentRectificationPlanService;

    /**
     * 查询内部事件整改计划列表
     */
    @PreAuthorize(hasPermi = "business:rectificationPlan:list")
    @GetMapping("/list")
    public TableDataInfo list(InternalIncidentRectificationPlan internalIncidentRectificationPlan)
    {
        startPage();
        List<InternalIncidentRectificationPlan> list = internalIncidentRectificationPlanService.selectInternalIncidentRectificationPlanList(internalIncidentRectificationPlan);
        return getDataTable(list);
    }

    /**
     * 导出内部事件整改计划列表
     */
    @PreAuthorize(hasPermi = "business:rectificationPlan:export")
    @Log(title = "内部事件整改计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InternalIncidentRectificationPlan internalIncidentRectificationPlan) throws IOException
    {
        List<InternalIncidentRectificationPlan> list = internalIncidentRectificationPlanService.selectInternalIncidentRectificationPlanList(internalIncidentRectificationPlan);
        ExcelUtil<InternalIncidentRectificationPlan> util = new ExcelUtil<InternalIncidentRectificationPlan>(InternalIncidentRectificationPlan.class);
        util.exportExcel(response, list, "内部事件整改计划数据");
    }

    /**
     * 获取内部事件整改计划详细信息
     */
    @PreAuthorize(hasPermi = "business:rectificationPlan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(internalIncidentRectificationPlanService.selectInternalIncidentRectificationPlanById(id));
    }

    /**
     * 新增内部事件整改计划
     */
    @PreAuthorize(hasPermi = "business:rectificationPlan:add")
    @Log(title = "内部事件整改计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InternalIncidentRectificationPlan internalIncidentRectificationPlan)
    {
        return AjaxResult.success(internalIncidentRectificationPlanService.insertInternalIncidentRectificationPlan(internalIncidentRectificationPlan));
    }

    /**
     * 修改内部事件整改计划
     */
    @PreAuthorize(hasPermi = "business:rectificationPlan:edit")
    @Log(title = "内部事件整改计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InternalIncidentRectificationPlan internalIncidentRectificationPlan)
    {
        return toAjax(internalIncidentRectificationPlanService.updateInternalIncidentRectificationPlan(internalIncidentRectificationPlan));
    }

    /**
     * 删除内部事件整改计划
     */
    @PreAuthorize(hasPermi = "business:rectificationPlan:remove")
    @Log(title = "内部事件整改计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(internalIncidentRectificationPlanService.deleteInternalIncidentRectificationPlanByIds(ids));
    }

    @Override
    protected IWorkFlowService getService() {
        return internalIncidentRectificationPlanService;
    }
}
